from matplotlib import pyplot as plt
from typing import Callable, Iterable


def _draw(func: Callable[[float], float], x: Iterable[float], color: str):
    x = list(x)
    plt.plot(x, [func(v) for v in x], color=color)


plt.subplot(211)
_draw(lambda x: x ** 2, (i / 10 for i in range(-10, 10 + 1, 1)), "b")
plt.title("平方曲线")

plt.subplot(212)
plt.xticks([i / 10 for i in range(0, 10 + 1, 1)])
_draw(lambda x: 1 / x, (i / 10 for i in range(1, 10 + 1, 1)), "g")
plt.title("倒数曲线")

# plt.subplots_adjust(hspace=0.6)

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.show()
